package com.xiaofeng.Hello;

import java.util.Random;
import java.util.Scanner;

public class Java5 {
    public static void main(String[] args) {
        //猜数字小游戏

        //生成随机数字
        Random r = new Random();
        //int a=r.nextInt(100);//0~99
        //int a=r.nextInt(91)+3;//0~93
        int a=r.nextInt(51)+1;

        //输入数字
        System.out.printf("请输入你猜测的数字：");
        Scanner sc =new Scanner(System.in);
        int guess = sc.nextInt();

        int cout=5;
        while(--cout>0){
            if(guess==a){
                System.out.printf("恭喜你猜对了!");
                break;
            }
            else {
                if(guess>a) {
                    System.out.printf("对不起，你猜大了！还剩 %d 次机会\n", cout);
                }
                else{
                    System.out.printf("对不起，你猜小了！还剩 %d 次机会\n", cout);
                }
            }
            System.out.printf("请输入你猜测的数字：");
            guess = sc.nextInt();

        }
        System.out.printf("这个数字是为 %d ",a);
    }
}
